﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class TranslateMatchSentences : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            if (ou.UserAccessLevel == "1" || ou.UserAccessLevel == "0")
            {
                Response.Redirect("~/GeneralMessage.aspx?MessageString=" + ou.UserAccessLevel);
            }
            
            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=274ggdizz5!lk");

            string Language = GND.ReadNivdalIntData("UserId", "Nivdal_GetUserTranslateLanguage", ou.UserId);
            if ((Language == null) || (Language == "0"))
                Response.Redirect("GeneralMessage.aspx?MessageString=k882m299nnqmhtsd");
            else if (Language == "2")
                Response.Redirect("TranslateEnglish.aspx");
            else
            {
                LanguageHiddenField.Value = Language;
                if (!IsPostBack)
                {
                    TranslateDataSource.SelectParameters.Add("UserId", ou.UserId);
                    TranslationStatusDataSourse.SelectParameters.Add("UserId", ou.UserId);
                }
            }
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }

        protected void SkipSentence(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            string SentenceNum = (MatchSentenceTranslateListView.Items[0].FindControl("SentenceNumHiddenField") as HiddenField).Value;
            MessageLabel.Text = GND.ReadNivdalStringData("UserId", "SentenceNum", "Nivdal_IgnoreMatchSentenceTranslation", ou.UserId, SentenceNum);
            StatusForumView.DataBind();
            MatchSentenceTranslateListView.DataBind();
        }

        protected void SubmitButtonClick(object sender, EventArgs e)
        {
            string Answer = " ";
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string SentenceNum, EventType, Param1, Param2, Param3, Part, SentenseNumber, Data;
            foreach (ListViewItem item in MatchSentenceTranslateListView.Items)
            {
                SentenceNum = (item.FindControl("SentenceNumHiddenField") as HiddenField).Value;
                EventType = (item.FindControl("EventTypeHiddenField") as HiddenField).Value;
                Param1 = (item.FindControl("Param1HiddenField") as HiddenField).Value;
                Param2 = (item.FindControl("Param2HiddenField") as HiddenField).Value;
                Param3 = (item.FindControl("Param3HiddenField") as HiddenField).Value;
                if ((Param1 == null) || (Param1 == ""))
                    Param1 = "-1";
                if ((Param2 == null) || (Param2 == ""))
                    Param2 = "-1";
                if ((Param3 == null) || (Param3 == ""))
                    Param3 = "-1";
                Part = (item.FindControl("PartHiddenField") as HiddenField).Value;
                SentenseNumber = (item.FindControl("SentenseNumberHiddenField") as HiddenField).Value;
                Data = (item.FindControl("TranslateTextBox") as TextBox).Text.Trim();

                Answer += GND.ReadNivdalStringData("Language", "SentenceNum", "EventType", "Param1", "Param2", "Param3", "Part", "SentenseNumber",
                                        "Data", "Nivdal_TranslateMatchSentencePart", LanguageHiddenField.Value, SentenceNum, EventType, Param1, Param2, Param3,
                                        Part, SentenseNumber, Data);
                Answer += "<br />";
            }
            MessageLabel.Text = Answer;
            StatusForumView.DataBind();
            MatchSentenceTranslateListView.DataBind();
        }

        protected string TranslationLanguageString(object LanguageName)
        {
            return (Resources.Resource.Translate_YouTranslateToLabelText + " " + LanguageName.ToString());
        }

        protected bool DescriptionExists(object Description)
        {
            return (Description.ToString().Length > 0);
        }
    }
}